<template>
    <div>
        <div class="searchInput">
            <div class="xia">
                <div class="kuang">
                    <div>
                        优惠券名称： <el-input placeholder="请输入优惠券名称"></el-input>&emsp;&emsp13;
                    </div>
                    <div>
                        类型： <el-select style="width: 108px;" v-model="searchType" placeholder="请选择">
                                <el-option
                                v-for="item in typeOptions"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </div>
                    <div style="margin-left: 20px;">
                        状态： <el-select style="width: 108px;" v-model="searchState" placeholder="请选择">
                            <el-option
                            v-for="item in stateOption"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                        </el-option>
                    </el-select>&emsp;&emsp13;
                </div>
                <div>
                    <span class="demonstration">&emsp;&emsp;&emsp;时间： </span>
                    <el-date-picker
                    v-model="searchDate"
                    type="daterange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期">
                    </el-date-picker>
                </div>
            </div>
            <div class="btns">
                <el-button class="chaxun">查询</el-button>
                <el-button class="reset">重置</el-button>
            </div>
        </div><br>
    </div>
    <div class="addBtn">
        <el-button class="newAdd" @click="addCoupon(0)"><i class="el-icon-plus"></i>新增</el-button>
    </div>
        <!-- 数据 -->
        <el-table
            :header-cell-style="{background:'#e8efff',color:'#000000'}"
            :data="lockTableData"
            :loading="loading"
            style="width: 100%">
            <el-table-column
            type="selection"
            width="55">
            </el-table-column>
            <el-table-column prop="order" label="序号" width="60">
                <template v-slot="scope">
                    <div style="color:#949BBE;">
                        {{ scope.row.order }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="number" label="编号">
                <template v-slot="scope">
                    <div style="color:#949BBE;">
                        {{ scope.row.number }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="coupon_name" label="优惠券名称">
                <template v-slot="scope">
                    <div style="color:#949BBE;">
                        {{ scope.row.coupon_name }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="coupon_type" label="类型">
                <template v-slot="scope">
                    <div style="color:#949BBE;">
                       <span v-if="scope.row.coupon_type == 0">折扣券</span>
                       <span v-if="scope.row.coupon_type == 1">折扣券</span>
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="content" label="优惠内容">
                <template v-slot="scope">
                    <div style="color:#949BBE;">
                        {{ scope.row.content }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="state" label="状态">
                <template v-slot="scope">
                    <div style="color:#949BBE;">
                        <span v-if="scope.row.state == 0">下架</span>
                        <span v-if="scope.row.state == 1">上架</span>
                        <span v-if="scope.row.state == 2">已过期</span>
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="duration" label="有效期">
                <template v-slot="scope">
                    <div style="color:#949BBE;">
                        {{ scope.row.duration1 }}-{{ scope.row.duration2 }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="create_time" label="创建时间">
                <template v-slot="scope">
                    <div style="color:#949BBE;">
                        {{ scope.row.create_time }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="address" label="操作" width="300">
                <template v-slot="scope">
                    <div class="scope" style="color:#949BBE;">
                        <span class="editBtn edit" @click="edit(scope.row.id)">编辑</span>
                        <span v-if="scope.row.state == 0" class="detailBtn xiajia" @click="changeState(scope.row.id,1)">下架</span>
                        <span v-if="scope.row.state == 1" class="detailBtn shang" @click="changeState(scope.row.id,0)">上架</span>
                        <span class="detailBtn detail" @click="goDetail(scope.row.id)">领取详情</span>
                        <span class="detailBtn del" @click="delete(scope.row.id)">删除</span>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <Pagination />
        <!-- 添加/详情/编辑 -->
        <el-dialog center :close-on-click-modal="false" width="636px" top="20vh" :visible.sync="newVisible">
            <template slot="title">
                <div class="dialog_title">
                    {{ dialogTitle }}
                </div>
            </template>
            <el-form label-position="right" :rules="rules" ref="ruleFormLock" label-width="120px" :model="gunInfoForm">
                <el-form-item prop="real_pay" label="实付金额:" >
                    <el-input v-model="gunInfoForm.real_pay" autocomplete="off" placeholder="请输入金额"></el-input>
                </el-form-item>
                <el-form-item prop="cause" label="退款原因:">
                    <el-input
                        style="width:423px ;background: #F0F1F6; outline: none;"
                        type="textarea"
                        :rows="5"
                        placeholder="请输入"
                        v-model="gunInfoForm.cause">
                    </el-input>
                </el-form-item>
                <el-form-item prop="money" label="退款金额:">
                    <el-input v-model="gunInfoForm.money" autocomplete="off" placeholder="请输入"></el-input>
                </el-form-item>
                <el-form-item>
                    <span class="beiZhu">备注：退款得金额会按原路返回，中途若产生手续费需退款人承担，谢谢！</span>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button class="formCancel" @click="newVisible = false">取消</el-button>
                <el-button class="formConfirm" type="primary"  @click="submitGunForm('ruleFormLock')">提交</el-button>
            </div>
        </el-dialog>
        <SuccessTip :isAgreeShow="isAgreeShow" :text="Success_text"/>
    </div>
</template>

<script>
import Pagination from '@/components/Pagination.vue'
import SuccessTip from '@/components/SuccessTip.vue'
    export default {
        components:{
            Pagination,SuccessTip
        },
        data() {
            return {
                loading:true,
                disabled:false,
                searchType:'',
                searchState:'',
                searchDate:'',
                typeOptions: [
                    {
                        value: null,
                        label: '请选择'
                    }, 
                    {
                        value: 0,
                        label: '折扣券'
                    }, 
                    {
                        value: 1,
                        label: '抵扣券'
                    }, 
                        ],
                stateOption: [
                    {
                    value: null,
                    label: '请选择'
                    }, 
                    {
                    value: 0,
                    label: '显示'
                    }, 
                    {
                    value: 1,
                    label: '隐藏'
                    }
                ],
                    lockTableData: [
                    {
                        order: 1,
                        number: '21021312',
                        coupon_name: '新人券',
                        coupon_type:0,
                        content: '5折',
                        duration1:'2023-01-01',
                        duration2:'2023-01-15',
                        create_time:'2023.03.03',
                        state:0,
                        id:1
                    },
                    {
                        order: 2,
                        number: '21021312',
                        coupon_name: '新人券',
                        content: '5折',
                        coupon_type:0,
                        duration1:'2023-01-01',
                        duration2:'2023-01-15',
                        create_time:'2023.03.03',
                        state:1,
                        id:1
                    },
                ],
                dialogTitle:'退款申请',
                confirmBtnText:"确认",
                newVisible:false,
                newDetailVisible:false,
                gunInfoForm:{}, //充电枪信息
                is_detail:false,
                rules:{
                    real_pay: [
                        { required: true, message: '请输入实付金额', trigger: 'blur' }
                    ],
                    cause: [
                        { required: true, message: '请输入退款原因', trigger: 'blur' }
                    ],
                    money: [
                        { required: true, message: '请输入退款金额', trigger: 'blur' }
                    ]
                },
                isAgreeShow:false,
                alert_title:'提现申请',
                Success_text:'操作成功'
            }
        },
        methods: {
            submitGunForm(formName){
                this.$refs[formName].validate((valid) => {
                if (valid) {
                    // 验证完成
                    alert('submit!');
                    this.newVisible = false
                } else {
                    console.log('error submit!!');
                    return false;
                }
                });
            },
            addCoupon(){
                this.$router.push("/addCoupon")
            },
            changeState(id,state){
                if(state == 0){
                    this.$confirm('您确定要下架吗？', '提示', {
                        cancelButtonText: '取消',
                        confirmButtonText: '确定',
                        title:'操作提示',
                        center: true
                    }).then(() => {
                        this.isAgreeShow = true
                        let t = setInterval(() => {
                            this.isAgreeShow = false
                        }, 2000);
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });
                        
                    });
                }else{
                    this.$confirm('您确定要上架吗？', '提示', {
                        cancelButtonText: '取消',
                        confirmButtonText: '确定',
                        title:'操作提示',
                        center: true
                    }).then(() => {
                        this.isAgreeShow = true
                        let t = setInterval(() => {
                            this.isAgreeShow = false
                        }, 2000);
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消删除'
                        });
                        
                    });
                }
            },
            goWithdraw(){
                this.newVisible = true
            },
            
            goDetail(id){
                this.$router.push({
                    path:'/couponDetail',
                    query:{
                        detail:1
                    }
                })
            },
        },
        
    }
</script>

<style lang="less" scoped>
.searchInput{
    text-align: left;
    font-size: 14px;
    height: 25.98px;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
    color: #666666 !important;
}
.el-input{
    width: 280px;
    height: 35.98px;
    font-size: 11.97px;
    color: #666666;
    background: #F0F1F6;
}
.el-input__inner{
  background-color: #F0F1F6;  
}
.el-select{
    width: 280px;
    height: 35.98px;
}
.kuang{
    float: left;
}

.el-button{
    background: transparent;
    border: none;
}
.chaxun{
    background: #165BFF;
    color: white;
}
.reset{
    background: #F0F1F6;
    color: #666666;
}
::v-deep .el-table th > .cell {
  text-align: center;
}

::v-deep .el-table .cell {
  text-align: center;
}
.editBtn{
    display: inline-block;
    margin-right: 8px;
    color: #000000;
    cursor: pointer;
}
.detailBtn{
    margin-right: 8px;
    display: inline-block;
    color: #165BFF;
    cursor: pointer;
}
.deleteBtn{
    display: inline-block;
    color: #FA698D;
    cursor: pointer;
}
.confirmButtonClass{
    background: #165bff;
}
#dialog .el-dialog__header {
    padding: 20px 20px 0px;
    background: #165BFF;
    text-align: left;
    font-weight: bold;
}
#dialog .el-dialog__body{
    height: 188px;
}
.formCancel,.formConfirm{
    width: 140px;
    height: 44px;
    border-radius: 4px 4px 4px 4px;
    border: none;
    opacity: 1;
}
.formCancel{
    background: white;
    border: 1px solid #F0F1F6;
}
.formConfirm{
    margin-left: 24px;
    background: #165BFF;
}
.dialog-footer{
    margin-top: -50px;
    text-align: center;
}
.el-dialog .el-input{
    width: 423px;
}
.el-dialog .el-select{
    width: 423px;
}
.dialog_title{
    margin-top: 24px;
    font-size: 16px;
    font-family: PingFang SC-Medium, PingFang SC;
    font-weight: 500;
    color: #000000;
}
.kuang>div{
    margin: 5px auto;
    display: inline-block;
}
.a .el-select{
    width: 108px;
}
.el-table{
    margin-top: 32px;
}
.xia{
    height: 36px;
}
.btns{
    float: right;
}
.btm{
    margin-top: 14px;
    margin-bottom: 10px;
}
.beiZhu{
    transform: translate(-50px,0);
    font-size: 12px;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
    color: #999999; 
}
.addBtn{
    text-align: left;
    margin-top: 52px;
}
.newAdd{
    background: #165BFF;
    color: white;
    width: 92px;
    height: 36px;
}
.edit{
    color: #09D796;
}
.xiajia{
    color: #FFB240;
}
.detail{
    color: #165BFF;
}
.shang{
    color: #8500ED;
}
.del{
    color: #FA698D;
}
</style>
<style>
.el-range-input{
    background: #f0f1f6;
    font-size: 12px !important;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
    color: #666666;
}
</style>

<style>
.el-message-box__header{
    font-size: 16px;
    font-family: PingFang SC-Medium, PingFang SC;
    font-weight: 500;
    color: #000000;
    line-height: 16px;
}
.el-message-box{
    width: 360px !important;
    height: 188px !important;
    background:#FFFFFF;
    border-radius: 4px 4px 4px 4px;
    opacity: 1;
}
.el-message-box--center .el-message-box__content{
    margin-top: 10px;
}
.el-message-box__message{
    font-size: 16px;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
    color: #666666;
}
.el-message-box__btns{
    margin-top:38px ;
}
.el-button--default{
    width: 80px;
    height: 36px;
    font-family: PingFang SC-Medium, PingFang SC;
    font-weight: 500;
}
.el-button--primary{
    width: 80px;
    height: 36px;
    background:#165BFF !important;
    border-radius: 4px 4px 4px 4px;
    border: 1px solid #165BFF;
    opacity: 1;
}

.el-range-input{
    background: #f0f1f6;
    font-size: 12px !important;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
    color: #666666;
}

.el-upload--picture-card{
    width: 75px;
    height: 75px;
    line-height: 82px;
    text-align: center;
}

</style>